import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dark_mode_demo/pages/my_home_page.dart';
import 'package:flutter_dark_mode_demo/provider/theme_setting_provider.dart';
import 'package:flutter_dark_mode_demo/theme/app_theme_mode.dart';
import 'package:flutter_dark_mode_demo/theme/theme_datas.dart';
import 'package:provider/provider.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await SpUtil.getInstance();

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider.value(value: ThemeSettingProvider())
      ],
      child: Consumer<ThemeSettingProvider>(
        builder: (context, themeSettingProvider, _) {
          return MaterialApp(
            title: 'Flutter Demo',
            debugShowCheckedModeBanner: false,
            theme: themeSettingProvider.mode == AppThemeMode.light ? kAppLightThemeData : kAppDarkThemeData,
            home: const MyHomePage(title: 'Flutter Demo Home Page'),
          );
        },
      ),
    );
  }
}